package com.open.capacity.reimburse.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.reimburse.entity.BillCondole2;
import com.open.capacity.reimburse.service.BillCondole2Service;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 慰问费用报销
 *
 * @author
 * @email
 * @date 2021-07-06 14:53:11
 */
@RestController
@RequestMapping("condole2s")
@Api(tags = "慰问费用报销")
public class BillCondole2Controller {

    @Autowired
    private BillCondole2Service billCanteen2Service;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_condole2:billcondole2:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billCanteen2Service.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_condole2:billcondole2:list')")
    public Result findById(String id) {
        return Result.succeed(billCanteen2Service.findById(id));
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findByProcessId")
    public Result findByProcessId(String processId) {
        return Result.succeed(billCanteen2Service.findById(processId));
    }

    /**
     * 校验
     */
    @RequestMapping("/verifyBill")
    public Result verifyBill(@RequestBody @Valid BillCondole2 bill) {
        billCanteen2Service.verifyBill(bill);
        return Result.succeed("校验成功");
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_condole2:billcondole2:save')")
    public Result save(@RequestBody @Valid BillCondole2 bill, String keyValue, Integer force) {
        if (StringUtils.isEmpty(keyValue)) {
            billCanteen2Service.save(bill, force);
        } else {
            bill.setId(keyValue);
            billCanteen2Service.update(bill, force);
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_condole2:billcondole2:delete')")
    public Result delete(@PathVariable String id) {
        billCanteen2Service.delete(id);
        return Result.succeed("删除成功");
    }

}
